<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>2.绘制图片</title>
  <style>
    canvas {
      border: 1px solid #000;
    }
  </style>
</head>
<body>
  <canvas width="800" height="600"></canvas>
  <script>
    const canvas = document.querySelector('canvas')
    const ctx = canvas.getContext('2d')

    // 1. 先创建图片实例
    const img = new Image()
    
    // 2. 加载图片
    img.src = './images/dog.png'
    
    // 3. 当图片加载完成之后再进行裁切或是复制
    img.onload = function(){
      ctx.drawImage(img,160,0,290,380,300,100,290,380)
    }
  </script>
</body>
</html>